//
//  BaseMarc.swift
//  YMSwiftUI
//
//  Created by anscen on 2022/3/18.
//

import Foundation

@_exported import SwiftUI
@_exported import Moya
@_exported import Alamofire
@_exported import HandyJSON
@_exported import SwiftyJSON
@_exported import SDWebImageSwiftUI

let shelfQueue     = BaseShelfQueue()// 书架表
let historyQueue   = BaseChapterQueue()//历史记录表

let SCREEN_WIDTH  :CGFloat  = UIScreen.main.bounds.size.width
let SCREEN_HEIGHT :CGFloat  = UIScreen.main.bounds.size.height

let grid_width  :CGFloat  = (SCREEN_WIDTH - 60) / 3 - 1
let grid_height :CGFloat  = grid_width * 1.35

let list_width :CGFloat = SCREEN_WIDTH - 30
let list_height:CGFloat = 130

let AppColor   = Color(UIColor(hex: "3991F0"))

//let AppX000000 = Color(UIColor(hex: "000000"))
//let AppX333333 = Color.app
//let AppX666666 = Color.appx666666()
//let AppX999999 = Color.appx999999()

let AppXDDDDDD = Color(UIColor(hex: "dddddd"))
extension String{
    var cover :String{
        var str :String = self
        if str.hasPrefix("/agent/"){
            str = str.replacingOccurrences(of: "/agent/", with: "")
        }
        str = str.removingPercentEncoding ?? ""
        return str
    }
}
extension Color{
    static func appx000000() ->Color{
        let color = UIColor { (trainCollection) -> UIColor in
            return UIColor(hex: trainCollection.userInterfaceStyle == .dark ? "999999" : "000000")
        }
        return Color(color)
    }
    static func appx333333() ->Color{
        let color = UIColor { (trainCollection) -> UIColor in
            return UIColor(hex: trainCollection.userInterfaceStyle == .dark ? "888888" : "333333")
        }
        return Color(color)
    }
    static func appx666666() ->Color{
        let color = UIColor { (trainCollection) -> UIColor in
            return UIColor(hex: trainCollection.userInterfaceStyle == .dark ? "777777" : "666666")
        }
        return Color(color)
    }
    static func appx999999() ->Color{
        let color = UIColor { (trainCollection) -> UIColor in
            return UIColor(hex: trainCollection.userInterfaceStyle == .dark ? "666666" : "999999")
        }
        return Color(color)
    }
    static func appxffffff() ->Color{
        let color = UIColor { (trainCollection) -> UIColor in
            return UIColor(hex: trainCollection.userInterfaceStyle == .dark ? "000000" : "ffffff")
        }
        return Color(color)
    }
}
extension UIImage{
    public static func imageWithColor(color:UIColor) -> UIImage{
        let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
        UIGraphicsBeginImageContext(rect.size)
        guard let context = UIGraphicsGetCurrentContext() else { return UIImage() }
        context.setFillColor(color.cgColor)
        context.fill(rect)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image ?? UIImage()
     }
}
